import influxdb

from clientUtil import devClient

# 创建InfluxDB客户端
client = devClient()

# 写入数据
# data = [
#     {
#         'measurement': 'cpu_usage',
#         'fields': {'value': 0.5}
#     }
# ]
# client.write_points(data)

'''

String sql = String.format(" select * from ActValWbl1 where equipmentAcode = '%s' ","虚拟设备4");
sql += " and equipmentNumber = '虚拟设备4' ";
sql += " and testFormItemMasterId  = '" + ids+"'" ;
sql += " ORDER BY time DESC LIMIT 1 ";

'''

# 查询数据
# query = " select * from ActValWbl1  "
# query += " where equipmentAcode   = '虚拟设备4' "
# query += " and equipmentNumber = '虚拟设备4' "
# query += " and testFormItemMasterId = '5162484331670' "
# query += " ORDER BY time DESC LIMIT 1 "


# query = " select count(*) from ActValWbl1 where equipmentAcode = '虚拟设备4'  and time >= '2025-03-07T00:00:00.000000Z'  and time <= '2025-03-07T10:50:17.000000Z'  and consigner =~ /.*ex_dengcc2.*/  and testFormNumber =~ /.*ST2024070052.*/ "
query = "select *  from ActValYsj29TA221108000516001001010820250428  "
result = client.query(query)
# # 获取查询结果的列表数据
data_list = list(result.get_points())
print(len(data_list))
#
# # 遍历列表数据
for index,data in enumerate(data_list):
    # print(f"索引值：{index}-----------------------------")
    print(index,data)


# client.delete_series(database="lims",measurement="ActValWbl54210")
# 删除数据
# query = "DELETE FROM ActValWbl1 where testFormItemMasterId = '5062398400283' limit 0 offset 2"
# result = client.query(query)
# print(result)
# print(result.rows)
# 关闭客户端
client.close()
